"use strict"

const moment = require('moment')
module.exports = app => {
    const { STRING, DATE, INTEGER } = app.Sequelize
    const Adver = app.model.define('adver', {
        id: {
            type: INTEGER,
            autoIncrement: true,
            primaryKey: true
        },
        name: {
            type: STRING,
            allowNull: false

        },
        img: {
            type: STRING,
            allowNull: false

        },
        url: {
            type: STRING,
            allowNull: false

        },
        remark: {
            type: STRING,
            allowNull: false

        },
        start: {
            type: INTEGER,
            allowNull: false

        },
        create_time: {
            type: DATE,
            allowNull: false,
            get() {
                return moment(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss')
            }
        },
        update_time: {
            type: DATE,
            allowNull: true,
            get() {
                const update_time = this.getDataValue('update_time')
                return update_time? moment(update_time).format('YYYY-MM-DD HH:mm:ss') : null
            }
        }
        
    })

    return Adver
}